/*var date = new Date();
date.setYear(2016);
date.setMonth(2);
date.setDate(1);
date.setHours(0);//获取当前小时数(0-23)
date.setMinutes(0);//获取当前分钟数(0-59)
date.setSeconds(0);//获取当前秒数(0-59)

var day = new Date(date.getTime() - 1000).getDate();

console.log(day)*/
$(function(){
	var date = new Date();
	var year = date.getFullYear();
	var mon = date.getMonth()+1;//月
	var dat = date.getDate();//日
	var day = date.getDay();//星期几
	var daytimeLi = $('.daytime .daytime-r ul li');
	var daytime = $('.daytime .daytime-r ul li span');
	$('.daytime .daytime-r ul li p').eq(day).css("color","red");
	daytime.eq(day).text(mon+"/"+dat);
	daytime.eq(day).attr('date', year + ' ' + mon + ' ' + dat);
	var a = day;
	while(a != 0) {
		a--;
		var k = day - a;
		var time = new Date(date.getTime() - k * (24*60*60*1000) );
		var y = time.getFullYear();
		var m = time.getMonth()+1;
		var d = time.getDate();
		if(m<10){
			m='0'+m
		};
		if(d<10){
			d='0'+d
		};
		daytime.eq(a).text(m+"/"+d);
		daytime.eq(a).attr('date', y + ' ' + m + ' ' + d);
	}
	while(a <= daytimeLi.length) {
		a++;
		var k = day - a;
		var time = new Date(date.getTime() - k * (24*60*60*1000) );
		var y = time.getFullYear();
		var m = time.getMonth()+1;
		var d = time.getDate();
		if(m<10){
			m='0'+m
		};
		if(d<10){
			d='0'+d
		};
		daytime.eq(a).text(m+"/"+d);
		daytime.eq(a).attr('date', y + ' ' + m + ' ' + d);
	}
	/*for (var i = day; i <= daytimeLi.length; i++) {
		//alert(i);	
		daytime.eq(i).attr('date', year + ' ' + mon + ' ' + b);
		daytime.eq(i).text(mon+"/"+b++)
	}*/
	$('.next').click(function(){
		var last = daytime.eq(6).attr('date');
		var devide = last.split(' ');
		var y = devide[0];
		var m = devide[1];
		var d = devide[2];
		var date = new Date();
		date.setYear(y);
		date.setMonth(m-1);
		date.setDate(d);
		for (var i = 0; i < 7; i++) {
			var newDate = new Date( date.getTime() + (i+1) * (24*60*60*1000) );
			var y = newDate.getFullYear();
			var m = newDate.getMonth()+1;
			var d = newDate.getDate();
			if(m<10){
				m='0'+m
			};
			if(d<10){
				d='0'+d
			};
			daytime.eq(i).text(m+"/"+d);
			daytime.eq(i).attr('date', y + ' ' + m + ' ' + d);
		}
	})
	$('.prev').click(function(){
		var last = daytime.eq(0).attr('date');
		var devide = last.split(' ');
		var y = devide[0];
		var m = devide[1];
		var d = devide[2];
		var date = new Date();
		date.setYear(y);
		date.setMonth(m-1);
		date.setDate(d);
		for (var i = 6; i >= 0; i--) {
			var newDate = new Date( date.getTime() - (7-i) * (24*60*60*1000) );
			var y = newDate.getFullYear();
			var m = newDate.getMonth()+1;
			var d = newDate.getDate();
			if(m<10){
				m='0'+m
			};
			if(d<10){
				d='0'+d
			};
			daytime.eq(i).text(m+"/"+d);
			daytime.eq(i).attr('date', y + ' ' + m + ' ' + d);
		}
	});
	$('.daytime .daytime-r ul li').click(function(){
		var txt = $(this).find('span').attr('date');
		var devide = txt.split(' ');
		var y = devide[0];
		var m = devide[1];
		var d = devide[2];
		//alert(txt);
		$('.Wdate').val(y+'-'+m+'-'+d);
	});
	//点击按钮选择日期
	$('#J-xl-2-btn').click(function(){
		laydate({
                elem: '#J-xl-2'
            });
	});
	//按照国家/地区条件查询
	$('.areaQuery .list-warp>li .bd ul li').click(function(){
		var t = $(this).hasClass('bg');
		//alert(t);
		if(t==false){
			$(this).addClass('bg');
		}
		if(t==true){
			$(this).removeClass('bg');
		}
	});
	for(var i=0;i<=3;i++){
		var oh = $('.areaQuery .list-warp>li ul').eq(i).outerHeight();
		//alert(oh);
		if(oh>=106){
			$('.areaQuery .list-warp>li ul').eq(i).addClass('ovf');
		}
	}
	
	$('.areaQuery .list-warp>li .hd').click(function(){
		var txt = $(this).find('.hd-r').text();
		var cla = $(this).next().find('ul').hasClass('ovf');
		var oh = $(this).next().outerHeight();
		//alert(cla);
		if(txt=='∨'){
			$(this).find('.hd-r').text('∧');
		}else{
			$(this).find('.hd-r').text('∨');
		}
		if(cla==true){
			$(this).next().find('ul').removeClass('ovf');
		}
		if(cla==false&&oh>=106){
			$(this).next().find('ul').addClass('ovf');
		}
		//alert(oh);
	});
})
